package com.chenfan.filestore.client;

import com.chenfan.ccp.common.result.R;
import com.chenfan.filestore.config.MultipartSupportConfig;
import com.chenfan.filestore.dto.WordToPdfDTO;
import com.chenfan.filestore.vo.FileDataResult;
import com.chenfan.filestore.vo.FileResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * @author K
 * @date 2021-05-27
 */
@FeignClient(name = "chenfan-cloud-filestore", contextId = "user1" ,url = "${feign.filestore:}",configuration = MultipartSupportConfig.class)
public interface FileClient {

    @ApiOperation("上传文件")
    @PostMapping(value = "/feign/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
    produces = MediaType.APPLICATION_JSON_VALUE)
    R<FileResult> uploadFile(@RequestPart(value = "file") MultipartFile file);

    @ApiOperation("根据文件ID获取二进制数据")
    @PostMapping(value = "/feign/file")
    R<List<FileDataResult>> getFileData(@RequestBody List<String> fileIdList);

    @ApiOperation("下载文件")
    @GetMapping("/file/download")
    feign.Response download(String fileId);

    @ApiOperation("读取图片")
    @GetMapping(value = "/file/views/{id}")
    feign.Response viewsImg(@PathVariable String id);

    @ApiOperation("文件下载")
    @GetMapping("/file/downloadWithoutReturnMsg")
    feign.Response downloadWithoutReturnMsg(@RequestPart("fileId") String fileId);

    @ApiOperation("Word文档转换为PDF")
    @PutMapping("/file/word-to-pdf")
    R<String> transferWordToPDF(@RequestBody WordToPdfDTO wordToPdf);

    @ApiOperation("Word文档转换为PDF")
    @PutMapping("/file/to-word")
    R<String> transferToWord(@RequestBody WordToPdfDTO wordToPdf);
}
